package com.lxw.study.behavioral.mediator;

import java.util.ArrayList;
import java.util.List;

public class ChatMediatorImpl implements ChatMediator{
    @Override
    public void sendMessage(String message, User user) {
        for (User u : getUsers()) {
            // 排除发送者，避免发送给自己
            if (!u.equals(user)) {
                u.receiveMessage(message);
            }
        }
    }
    public List<User> getUsers(){
        List<User> userList = new ArrayList<>();
        userList.add(new ChatUser(this,"张三"));
        userList.add(new ChatUser(this,"李斯"));
        userList.add(new ChatUser(this,"王武"));
        return userList;
    }
}
